<?php


namespace App\Model\Repository;


use App\Model\Base\ApiProject;

/**
 * Class ApiProjectRepository
 * @package App\Model\Repository
 * @property ApiRequestPresetRepository[]|\Illuminate\Database\Eloquent\Relations\HasMany $preset
 */
class ApiProjectRepository extends ApiProject
{
    /**
     * 读取项目id和项目名称映射数组
     * @return array
     */
    public static function getProjectMap()
    {
        return collect(self::all()->toArray())->mapWithKeys(function ($item) {
            return [$item['project_id'] => $item['project_name']];
        })->all();
    }

    public function preset()
    {
        return $this->hasMany(ApiRequestPresetRepository::class, 'project_id', 'project_id');
    }
}